<template>
	<view class="form-container">
		<!-- form演示 -->
		<view class="form-group">
			<form class="form-main" @submit="formSubmit">
				<view class="form-group">
					<h3>托盘号</h3>
					<view><input id="user-insert-line" name="input" placeholder="托盘编号" /></view>
				</view>
				<view class="form-group"><button class="btnsubmit" form-type="submit">确定</button></view>
				<view class="form-group"><button type="default" form-type="reset">重置</button></view>
			</form>
		</view>
	</view>
</template>

<script>
	import {
		login,
		editPasswd
	} from '@/api/user.js';
	export default {
		data() {
			return {
				fetching: false,
				password: true,
				tabIndex: 0,
				labelPosition: 'top',
				errorType: ['message'],
				border: false,
				model: {
					oldPassword: '',
					newPassword: '',
					checkNewPassword: ''
				},
				rules: {
					oldPassword: [{
						required: true,
						message: '请输入旧密码',
						trigger: 'change'
					}],
					newPassword: [{
						required: true,
						message: '请输入新密码',
						trigger: 'change'
					}],
					checkNewPassword: [{
						required: true,
						message: '请输入确认密码',
						trigger: 'change'
					}]
				},
				//屏幕高度
				screenHeight: 0,
			}
		},
		onLoad() {
			this.screenHeight = uni.getSystemInfoSync().windowHeight;
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			handleAdd() {
				uni.navigateTo({
					url: ""
				})
			},
			goLogin() {
				let that = this;
				that.$refs.uForm.validate(valid => {
					if (valid) {
						// 提交数据
						if (that.fetching) {
							return false;
						}
						that.fetching = true;
						// 显示loading状态
						uni.showLoading({
							mark: true,
							title: "提交中..."
						})
						editPasswd({
							userCode: uni.getStorageSync('usercode'), //登录账号
							oldPassword: that.model.oldPassword, //旧密码
							newPassword: that.model.newPassword, //新密码
							checkNewPassword: that.model.checkNewPassword //第二次新密码
						}).then((res) => {
							if (res && res.state == "ok") {
								uni.showToast({
									title: '修改密码成功，请使用新密码重新登录',
									icon: 'none',
									duration: 1500
								})
								setTimeout(() => {
									that.fetching = false;
									uni.hideLoading();
									uni.reLaunch({
										url: '/pages/auth/login/login'
									})
								}, 500)
							} else if (res && res.state == "fail") {
								that.fetching = false;
								uni.hideLoading();
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 3000
								})
							}
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #EEF0F4;
		font-size: 18px;
	}
	
	.btnsubmit{
		margin-top: 80px;
	}

	.form {
		margin-top: 35rpx;
		width: 100%;
		padding: 0 20rpx;
	}
	.form-group{
		
		padding: 20rpx 30rpx 0rpx 30rpx;
	}
	
	#user-insert-line::before {
	    position: absolute;
	    right: 25px;
	    bottom: 0;
	    top: 5rem;
	    left: 30px;
	    height: 1px;
	    content: '';
	    -webkit-transform: scaleY(.5);
	    transform: scaleY(.5);
	    background-color: #c8c7cc;
	}


</style>
